package org.peoples.rooms {
	
	import com.qualityattributes.collections.sets.HashSet;
	import com.qualityattributes.collections.sets.ISet;
	import com.qualityattributes.utils.IEqualable;
	
	import mx.collections.ArrayCollection;
	
	import org.peoples.messages.Message;
	import org.peoples.users.User;
	import com.qualityattributes.lang.QString;
	
	[RemoteClass(alias="org.peoples.rooms.RoomProperties")]
	[Bindable]
	public class RoomProperties implements IEqualable {
		
		public var ID:int;
		public var name:String;
		public var description:String;
		public var creationDate:Date;
		
		private var _users:ISet;
		private var _messages:ArrayCollection;
		
		public function RoomProperties():void {
			this._users = new HashSet();
		}
		
		public function addMessage(message:Message):Boolean {
			this._messages.addItem(message);
			return true;
		}
		
		public function addUser(user:User):Boolean {
			if (!this._users.contains(user)) {
				this._users.add(user);
				return true;
			}
			
			return false;
		}
		
		public function equals(o:Object):Boolean {
			if (this == o)
				return true;
				
			if (! (o is RoomProperties))
				return false;
				
			var r:RoomProperties = o as RoomProperties;
			if (name == r.name)
				return true;
				
			return false;
		}
		
		public function hashCode():int {
			var qStr:QString = new QString(name);
			return qStr.hashCode();
		}
		
		public function removeUser(user:User):Boolean {
			return this._users.remove(user);
		}
		
		public function toString():String {
			return "Room " + ID + ": " + name;
		}
		
		
		public function get users():ISet {
			return this._users;
		}
		
	}
	
}